$(function(){
    var auditInsurance_datagrid,auditInsurance_form;
    auditInsurance_datagrid = $("#auditInsurance_datagrid");
    auditInsurance_form = $("#auditInsurance_form");
    auditInsurance_datagrid.datagrid({
        fit:true,
        fitColumns:true,
        pagination:true,
        rownumbers:true,
        singleSelect:true,
        url:'/auditInsurance/auditInsurancePassDate',
        columns:[[
            {field:'bill',title:'申请单号',width:10,align:'center',formatter:billFormatter},
            {field:'batchNumber',title:'批单号',width:10,align:'center',formatter:batchNumberFormatter},
            {field:'client',title:'投保人',width:10,align:'center',formatter:clientFormatter},
            {field:'applyTime',title:'申请时间',width:10,align:'center',formatter:applyTimeFormatter},
            {field:'product',title:'产品名称',width:10,align:'center',formatter:productFormatter},
            {field:'engineNumber',title:'发动机号',width:10,align:'center',formatter:engineNumberFormatter},
            {field:'mainChassis',title:'车架号',width:10,align:'center',formatter:mainChassisFormatter}
        ]],
    });

    $("#dialog_tips").dialog({
        title: '保单详细',
        width: 1000,
        height: 500,
        closed: true
    })

    $("#auditInsurancePass_dialog").dialog({
        title: '历史痕迹',
        width: 1000,
        height: 500,
        closed: true
    })



    var cmdObj={

        search:function () {
            var engineNumber  = $("[name=engineNumber]").val();
            var mainChassis  = $("[name=mainChassis]").val();
            var cliendName  = $("[name=cliendName]").val();
            var productId  = $("[name=productId]").val();
            var billNumber  = $("[name=billNumber]").val();
            var billMinDate  = $("[name=billMinDate]").val();
            var billMaxDate  = $("[name=billMaxDate]").val();

            if (billMinDate == ""){
                billMinDate = '1949-10-01'
            }
            if (billMaxDate == ""){
                billMaxDate = '2088-10-01'
            }
            auditInsurance_datagrid.datagrid("load",{
                engineNumber:engineNumber,
                mainChassis:mainChassis,
                cliendName:cliendName,
                productId:productId,
                billNumber:billNumber,
                billMinDate:billMinDate,
                billMaxDate:billMaxDate
            })
        },
        reload:function () {
            auditInsurance_form.form("clear");
            var engineNumber  = $("[name=engineNumber]").val();
            var mainChassis  = $("[name=mainChassis]").val();
            var cliendName  = $("[name=cliendName]").val();
            var productId  = $("[name=productId]").val();
            var billNumber  = $("[name=billNumber]").val();
            var billMinDate  = $("[name=billMinDate]").val();
            var billMaxDate  = $("[name=billMaxDate]").val();

            if (billMinDate == ""){
                billMinDate = '1949-10-01'
            }
            if (billMaxDate == ""){
                billMaxDate = '2088-10-01'
            }
            auditInsurance_datagrid.datagrid("load",{
                engineNumber:engineNumber,
                mainChassis:mainChassis,
                cliendName:cliendName,
                productId:productId,
                billNumber:billNumber,
                billMinDate:billMinDate,
                billMaxDate:billMaxDate
            })
        },
        history:function(){
            var rowData = auditInsurance_datagrid.datagrid("getSelected");
            if (rowData) {
                $("#auditInsurancePass_datagrid").datagrid({
                    fit: true,
                    fitColumns: true,
                    rownumbers: true,
                    url: '/auditInsurance/auditHistoryData?id=' +rowData.id ,
                    columns: [[
                        {field: 'inputUser', title: '任务录入人', width: 10, align: 'center',formatter:inputUserFormatter},
                        {field: 'iuDept', title: '录入人部门', width: 10, align: 'center',formatter:iuDeptFormatter},
                        {field: 'billTime', title: '任务录入时间', width: 10, align: 'center',formatter:billTimeFormatter},
                        {field: 'correctUser', title: '批改人', width: 10, align: 'center',formatter:correctUserFormatter},
                        {field: 'examineUser', title: '审核人', width: 10, align: 'center',formatter:examineUserFormatter},
                        {field: 'euDept', title: '审核人部门', width: 10, align: 'center',formatter:euDeptFormatter},
                        {field: 'pushTime', title: '审核开始时间', width: 10, align: 'center'},
                        {field: 'anp', title: '审核结束时间', width: 10, align: 'center',formatter:anpFormatter}
                    ]],
                });
                $("#auditInsurancePass_dialog").dialog("open");
            }else {
                $.messager.alert("瞧我这暴脾气", "你丫要我弄谁呢?能不闹吗?", "warning");
            }
        },

        query:function () {
            var rowData = auditInsurance_datagrid.datagrid("getSelected");
            if (rowData) {
                var billId = rowData.bill.id;
                $.get("/orderBill/queryDetailData?id=" + billId, function (selectedRow) {
                    //客户信息
                    selectedRow["realName"]=selectedRow.client.realName;
                    selectedRow["idCardType"]=selectedRow.client.idCardType;
                    selectedRow["idCardNumber"]=selectedRow.client.idCardNumber;
                    //承保信息表单
                    selectedRow["organizationId"]=selectedRow.organization.id;
                    selectedRow["organizationName"]=selectedRow.organization.organizationName;
                    selectedRow["productId"]=selectedRow.product.id;
                    selectedRow["productName"]=selectedRow.product.name;
                    selectedRow["rate"]=selectedRow.product.rate;
                    selectedRow["basicPrice"]=selectedRow.product.basicPrice;
                    selectedRow["paymentPrice"]=selectedRow.product.paymentPrice;
                    selectedRow["coveragePrice"]=selectedRow.product.coveragePrice;
                    //录入人
                    selectedRow["inputUserName"]=selectedRow.inputUser.name;
                    selectedRow["applyTime1"]=selectedRow.applyTime;
                    $("#applyTime1").datebox('setValue','6/1/2012')
                    //车库汽车信息
                    selectedRow["sn"]=selectedRow.carInfo.sn;
                    selectedRow["carType"]=selectedRow.carInfo.carType;
                    selectedRow["basesNumber"]=selectedRow.carInfo.basesNumber;
                    selectedRow["airRelease"]=selectedRow.carInfo.airRelease;
                    selectedRow["seatNumber"]=selectedRow.carInfo.seatNumber;
                    selectedRow["rateDuality"]=selectedRow.carInfo.rateDuality;
                    selectedRow["mainChassis"]=selectedRow.carInfo.mainChassis;
                    selectedRow["engineNumber"]=selectedRow.carInfo.engineNumber;
                    selectedRow["newCarPrice"]=selectedRow.carInfo.newCarPrice;
                    selectedRow["importation"]=selectedRow.carInfo.importation;
                    selectedRow["power"]=selectedRow.carInfo.power;
                    //客户车辆信息
                    selectedRow["clientCarInfo.id"]=selectedRow.clientCarInfo.id;
                    selectedRow["hasCarNumber"]=selectedRow.clientCarInfo.hasCarNumber;
                    selectedRow["newCar"]=selectedRow.clientCarInfo.newCar;
                    selectedRow["foreignCar"]=selectedRow.clientCarInfo.foreignCar;
                    selectedRow["transferCar"]=selectedRow.clientCarInfo.transferCar;
                    selectedRow["carNumberType"]=selectedRow.clientCarInfo.carNumberType;
                    selectedRow["carNumber"]=selectedRow.clientCarInfo.carNumber;
                    selectedRow["registerTime"]=selectedRow.clientCarInfo.registerTime;
                    selectedRow["workingNature"]=selectedRow.clientCarInfo.workingNature;
                    selectedRow["workingArea"]=selectedRow.clientCarInfo.workingArea;
                    selectedRow["transferTime"]=selectedRow.clientCarInfo.transferTime;
                    selectedRow["driverInfo"]=selectedRow.clientCarInfo.driverInfo;
                    selectedRow["driverYears"]=selectedRow.clientCarInfo.driverYears;
                    selectedRow["fleet"]=selectedRow.clientCarInfo.fleet;
                    selectedRow["queryNumber"]=selectedRow.clientCarInfo.queryNumber;
                    selectedRow["relationToClient"]=selectedRow.clientCarInfo.relationToClient;
                    selectedRow["checkNumber"]=selectedRow.clientCarInfo.checkNumber;
                    $("#form_orderTips").form("load",selectedRow)
                    $("#dialog_tips").dialog("open")
                }, "json")
            } else {
                $.messager.alert("瞧我这暴脾气", "你丫要我弄谁呢?能不闹吗?", "warning");
            }
        }









    };


    $("a[data-cmd]").on("click",function(){
        var cmd = $(this).data("cmd");
        cmdObj[cmd]();
    })
});




function inputUserFormatter(value,row,index){
    console.log(row);
    return row.inputUser?row.inputUser.name :"";
}

function iuDeptFormatter(value,row,index){
    return row.iuDept?row.iuDept.name :"";
}

function billTimeFormatter(value,row,index){
    return row.bill?row.bill.applyTime :"";
}

function correctUserFormatter(value,row,index){
    return row.correctUser?row.correctUser.name :"";
}

function examineUserFormatter(value,row,index){
    return row.examineUser?row.examineUser.name :"";
}

function euDeptFormatter(value,row,index){
    return row.euDept?row.euDept.name :"";
}

function anpFormatter(value,row,index){
    return row.anp?row.anp.auditTime :"";
}

















//申请单号
function billFormatter(value,row,index){
    return value? value.orderBillNumber:"";
}
//批单号
function batchNumberFormatter(value,row,index){
    return row.info? row.info.batchNumber:"";
}
//投保人
function clientFormatter(value,row,index){
    return value? value.realName:"";
}

//申请时间
function applyTimeFormatter(value,row,index){
    return row.bill? row.bill.applyTime:"";
}

//产品名称
function productFormatter(value,row,index){
    return value? value.name:"";
}
//发动机
function engineNumberFormatter(value,row,index){
    return row.car? row.car.engineNumber:"";
}
//车架
function mainChassisFormatter(value,row,index){
    return row.car? row.car.mainChassis:"";
}







